Skip to content

Conversation

@NSabirov
Copy link

@NSabirov NSabirov commented Feb 5, 2023

Ради интереса еще сделал обратный отклик из Ресивер фрагмента в Продюсер фрагмент.
Но тема даггера все еще сложновата =( Буду пересматривать лекции

Copy link
Contributor

@antonkazakov antonkazakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Привет. Оставил замечания


override fun onCreate() {
super.onCreate()
appComponent = DaggerApplicationComponent.factory().create(this, DataModule())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А зачем ты модуль прокинул в фабрику?

@BindsInstance
@Named("ApplicationContext")
appContext: Context,
dataModule: DataModule,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это нужно убрать


@Named("ApplicationContext")
fun provideContext(): Context
fun provideColorFlow(): MutableSharedFlow<Int>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно их перенести на уровень активити компонента



@Module
@Named("DataModule")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А это зачем?)


@Module
@Named("DataModule")
class DataModule {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Подключи его в активитикомпонент

import javax.inject.Named

class ViewModelProducer @Inject constructor(
@Named("ActivityContext") private val context: Context,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У тебя здесь будет утечка памяти, потому что ссылка на активити контекс будет жить в ВМ, а активити будет пересоздана

@Named("ActivityContext") private val context: Context,
private val colorGenerator: ColorGenerator,
private val colorFlow: MutableSharedFlow<Int>,
private val stateFlow: MutableSharedFlow<State>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не совсем понял зачем тебе 2 флоу

private val colorFlow: MutableSharedFlow<Int>,
private val stateFlow: MutableSharedFlow<State>
) : ViewModel(){
val state = MutableLiveData<State>()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Правильнее конечно чтобы публичная лайвдата была иммутабельная


override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
(requireActivity() as MainActivity).mainActivityComponent
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я бы это перенес в oncreate/onattach, onViewCreated слишком часто вызывается


class ViewModelReceiver @Inject constructor(
@Named("ApplicationContext") private val context: Context,
private val colorFlow: MutableSharedFlow<Int>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Неправильно что у тебя в приемнике есть возможность эмитить эвенты во флоу, здесь должен быть SharedFlow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants